<template>
  <view class="">
    <view class="indexeditlist">
      <view class="indexedititem">
        <text>租赁区库存:</text>
        <input
          v-model="leasestock"
          type="number"
          placeholder="请输入租赁区库存"
        />
      </view>

      <view class="indexedititem">
        <text>出售区库存:</text>
        <input
          v-model="salestock"
          type="number"
          placeholder="请输入出售区库存"
        />
      </view>

      <view class="indexedititem">
        <text>仓库:</text>
        <input v-model="showstock" type="number" placeholder="请输入仓库" />
      </view>

      <view class="indexedititem">
        <text>清洗中库存:</text>
        <input
          v-model="cleanstock"
          type="number"
          placeholder="请输入清洗中库存"
        />
      </view>

      <view class="cardtypeitem">
        <text>请选择状态:</text>
        <u-radio-group @change="radioGroupChangeStatus" v-model="status">
          <u-radio
            :icon-size="40"
            v-for="(item, index) in statuslist"
            :key="index"
            :name="item.value"
            :disabled="item.disabled"
          >
            {{ item.name }}
          </u-radio>
        </u-radio-group>
      </view>
    </view>
    <view class="indexbtn" @click="handleEdit"> 提交 </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      //   上架/下架
      status: 1,
      statuslist: [
        {
          value: 1,
          name: "上架",
          disabled: false,
        },
        {
          value: 2,
          name: "下架",
          disabled: false,
        },
      ],
      skuid: "",
      // 租赁区库存
      leasestock: "",
      // 出售区库存
      salestock: "",
      // 清洗中库存
      cleanstock: "",
      // 仓库
      showstock: "",
    };
  },
  watch: {},
  methods: {
    radioGroupChangeStatus(status) {
      console.log(status);
    },

    // 修改sku
    handleEdit() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.goods/goodsSkuStockEdit", //仅为示例，并非真实接口地址。
        data: {
          skuid: this.skuid,
          lease_stock: this.leasestock,
          sale_stock: this.salestock,
          show_stock: this.showstock,
          status: this.status,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code == 0) {
            uni.showToast({
              title: res.data.msg,
              icon: "error",
              duration: 2000,
            });
          } else if (res.data.code == 1) {
            uni.showToast({
              title: res.data.msg,
              icon: "success",
              duration: 3000,
            });

            // 返回详情
            uni.navigateTo({
              url: "../goodsadmin/goodsadmin",
            });
          }
        },
      });
    },
    // 根据skuid获取列表信息
    getSkuList() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.goods/goodsSkuStockEdit", //仅为示例，并非真实接口地址。
        data: {
          skuid: this.skuid,
        },
        method: "GET",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code == 1) {
            console.log(res.data.data);
            // 租赁区库存
            this.leasestock = res.data.data.lease_stock;
            // 出售区库存
            this.salestock = res.data.data.sale_stock;
            // 清洗中库存
            this.cleanstock = res.data.data.clean_stock;
            // 仓库
            this.showstock = res.data.data.show_stock;
            this.status = res.data.data.status;
          }
        },
      });
    },
  },
  onLoad(option) {
    console.log(option.id);
    this.skuid = option.id;
  },
  mounted() {
    this.getSkuList();
  },
};
</script>

<style>
.indexeditlist {
  width: 90%;
  margin: 4% 5%;
}
.indexedititem {
  border-bottom: 1px solid #e6e6e6;
  padding: 5% 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.indexedititem text {
  width: 160rpx;
  color: #313131;
}
.indexedititem input {
  font-size: 28rpx;
  width: 500rpx;
  color: #828282;
  text-align: right;
}
.indexbtn {
  width: 80%;
  margin: 2% 10%;
  text-align: center;
  background: red;
  font-size: 32rpx;
  line-height: 3;
  color: #fff;
  border-radius: 60rpx;
  margin-top: 100rpx;
}
.cardtypeitem {
  border-bottom: 1px solid #e6e6e6;
  padding: 5% 0;
  display: flex;
  justify-content: space-between;
}
.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5% 0;

  border-bottom: 1px solid #e6e6e6;
}
.cardtypeitem {
  border-bottom: 1px solid #e6e6e6;
  padding: 5% 0;
  display: flex;
  justify-content: space-between;
}
</style>
